/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package xdxn.editor.studio.data;

import java.util.HashMap;

/**
 *
 * @author Cai Han
 */
public class ProjectManager {

    private final HashMap<String, Project> _map;
    private Project _current;

    private ProjectManager() {
        _map = new HashMap<>();
    }

    public void current(Project p) {
        this._current = p;
    }

    public Project current() {
        return this._current;
    }

    public Project create(String projectName) {
        if (!_map.containsKey(projectName)) {
            Project p = new Project();
            p.name = projectName;
            _map.put(projectName, p);
            this._current = p;
            return p;
        }
        return _map.get(projectName);
    }

    public Project get(String projectName) {
        return _map.get(projectName);
    }
    
    public void remove(){
        if(_current != null){
            _map.remove(_current.name);
        }
    }
    
    private static ProjectManager _instance;

    public static ProjectManager getInstance() {
        if (_instance == null) {
            _instance = new ProjectManager();
        }
        return _instance;
    }
}
